15. Exercise: Use Dimens Resources
L10 25 Using Dimens SC
Now it's your turn to complete this exercise yourself!
In the next two exercises we'll continue making the UI more consistent by replacing hardcoded layout dimensions and colors.
Let’s start with dimensions, by refactoring some of your hardcoded values into dimen resources that can be shared throughout the app.
1. Define a spacing_normal dimension resource.
In values/dimens.xml, inside the <resource> block, define a 16dp dimen value called spacing_normal:
<dimen name="spacing_normal">16dp</dimen>
2. Change guildline values to Material Design recommended value.
In home_fragment.xml, using a @dimen resource, change the end_grid guideline to the spacing_normal resource value.
app:layout_constraintGuide_end="@dimen/spacing_normal"
3. Replace 16dp values throughout the app.
Use the keyboard shortcut Ctrl-Shift-R (Cmd-Shift-R on a mac) to replace the 16dp to replace margin, padding, and guideline values throughout the app.**
Build and run your app to make sure it still looks correct.
If you want to start at this step, you can download this exercise from: Step.06-Exercise-Use-Dimens-Resources.
You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck, go back and watch the video again.
Once you’re done, you can check your solution against the solution we’ve provided here: Step.06-Solution-Use-Dimens-Resources, or using this git diff.
Task Description:
Complete the tasks below to replace hardcoded values with dimens resources.
Task Feedback:
Great job!
Reference documentation